package com.asset.dispoal.dic.service.commom;

import com.asset.dispoal.dic.domain.db.entity.GbDictDo;
import com.asset.dispoal.dic.domain.db.mapper.GbDictMapper;
import com.asset.dispoal.dic.dto.GbDicRequest;
import com.asset.dispoal.dic.service.converter.GbDicConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.date.DateTimeUtil;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.core.id.BaseIdeable;
import tech.mhuang.pacebox.springboot.protocol.Result;

/**
 * @author qr
 * @date 2022/2/24$
 */
@Component
public class GbDicInsertCommand implements BaseCommand<GbDicRequest, Result> {


    @Autowired
    GbDictMapper gbDictMapper;
    @Autowired
    BaseIdeable<String> snowFlake;

    @Override
    public Result execute(GbDicRequest request) {
        final GbDictDo gbDictDo = GbDicConverter.INSTANCE.reqToDo(request);
        gbDictDo.setDelFlag("0");
        gbDictDo.setId(snowFlake.generateId());
        gbDictDo.setCreateTime(DateTimeUtil.currentDate());
        gbDictMapper.insert(gbDictDo);
        return Result.ok();
    }
}
